package com.zynn.service.module.canal.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zynn.common.core.service.impl.BaseServiceImpl;
import com.zynn.feign.module.es.SyncEventFeignService;
import com.zynn.message.queue.constant.MqQueueNameConstant;
import com.zynn.message.queue.service.SenderService;
import com.zynn.service.module.canal.dao.GroupmembersMapper;
import com.zynn.service.module.canal.entity.Groupmembers;
import com.zynn.service.module.canal.service.GroupmembersService;
import com.zynn.common.core.utils.TypeConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘天元
 * @since 2018-07-02
 */
@Service
@Slf4j
public class GroupmembersServiceImpl extends BaseServiceImpl<GroupmembersMapper, Groupmembers> implements GroupmembersService {

    @Autowired
    private SyncEventFeignService syncEventFeignService;

    @Autowired
    private SenderService senderService;

    @Override
    public void handleInsert(Map<String, Object> columnsMap) {
        //senderService.send(MqQueueNameConstant.FIND_FRIEND_FROM_GROUPMEMBERS, columnsMap);
        senderService.send(MqQueueNameConstant.MIGRATE_GROUP_MEMBERS_ON_TIME, columnsMap);
        senderService.send(MqQueueNameConstant.MIGRATE_SPECIAL_GROUP_JOIN, columnsMap);
    }

//    @JmsListener(destination = MqQueueNameConstant.FIND_FRIEND_FROM_GROUPMEMBERS)
//    public void findDegOneFriend(Map<String, Object> columnsMap) {
//        log.info("FIND_FRIEND_FROM_GROUPMEMBERS:{}", columnsMap);
//        Long groupId = TypeConvertUtil.objectToLong(columnsMap.get("gmgroupid"));
//        List<Groupmembers> memberList = super.selectList(new EntityWrapper<Groupmembers>().eq("gmgroupid", groupId).last("limit 101"));
//        int groupMemberLimitSize = 100;
//        if(memberList.size() >= groupMemberLimitSize ) {
//            return;
//        }
//        if(!CollectionUtils.isEmpty(memberList)) {
//            for (Groupmembers groupmembers : memberList) {
//                Integer userId = groupmembers.getGmuserid();
//                log.info("计算{}一度好友", userId);
//                syncEventFeignService.initFriend(userId.longValue());
//            }
//        }
//    }
}
